<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>正则表达式</title>
    <script>
        function f1(){
            let inText = document.getElementById("inText").value;

            // 使用直接量语法定义正则表达式对象
            let regExp = /[a-z]/i;
            if(regExp.test(inText)){
                document.getElementById("s1").innerHTML = "<span style='color:green;'>格式正确</span>";
            }else{
                document.getElementById("s1").innerHTML = "<span style='color:red;'>格式有误</span>";
            }
        }
        function f2(){
            let inText = document.getElementById("inText").value;

            // 使用直接量语法定义正则表达式对象
            let regExp = new RegExp("[a-z]","i");
            if(regExp.test(inText)){
                document.getElementById("s1").innerHTML = "<span style='color:green;'>格式正确</span>";
            }else{
                document.getElementById("s1").innerHTML = "<span style='color:red;'>格式有误</span>";
            }
        }
        function f3(){
            let inText = document.getElementById("inText").value;
            // 使用直接量语法定义正则表达式对象
            let regExp = /^[a-z]{4,}$/i;
            if(regExp.test(inText)){
                document.getElementById("s1").innerHTML = "<span style='color:green;'>格式正确</span>";
            }else{
                document.getElementById("s1").innerHTML = "<span style='color:red;'>格式有误</span>";
            }
        }
    </script>
</head>
<body>
<input type="text" id="inText"><span id="s1"></span><br>
<button onclick="f1()">定义方式一</button><br>
<button onclick="f2()">定义方式二</button><br>
<button onclick="f3()">完整匹配</button><br>

</body>
</html>